package com.exsun.gateway.jt809.kafka.gps.check;

import exsun.jt808.data.upload_data.GpsData;
import exsun.jt808.data.upload_data.GpsStatusType;
import exsun.jt808.data.util.MapUtil;
import exsun.jt808.data.util.parse.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

public class GpsReasonableHandle {
    private static Logger logger = LoggerFactory.getLogger(GpsReasonableHandle.class);
    //key 设备号
    private static ConcurrentHashMap<String, GpsData> gpsCache = new  ConcurrentHashMap<>();

    public static void addGpsCache(GpsData gps){
        gpsCache.put(gps.dvo, gps);
    }

    public static GpsData getGpsCache(String devNo){
        if(gpsCache.containsKey(devNo))return gpsCache.get(devNo);
        return null;
    }

    /**
     * 是否为历史数据
     * @param gps
     * @return true：是 false：否
     */
    public static boolean gpsIsHistory(GpsData gps){
        GpsData last = getGpsCache(gps.dvo);
        //10分钟前的数据，则认为是历史的数据
        boolean bScap = new Date().getTime() - gps.getGdt().getTime() > 1000 * 600;
        if(bScap)return true;
        if(last == null)return false;
        if(last.gte > gps.gte){
            return true;
        }
        return false;
    }

}
